type CropStaffType = 'cropPlot' | 'cropRack';
import { CropStaff } from '.';
import { Vector3 } from 'three';
import { createCameraTween } from '../tools/useTween';
import GreenHouse from '../GreenHouse/GreenHouse';

interface EditParams<T extends CropStaff> {
  building: Editor.PlantAreaManagerOption['building'];
  controls: Editor.PlantAreaManagerOption['controls'];
  camera: Editor.PlantAreaManagerOption['camera'];
  staff: T;
}
export const editStrategies: Record<CropStaffType, (params: EditParams<CropStaff>) => void> = {
  cropPlot: () => {},
  cropRack: (params: EditParams<Editor.CropRack>) => {
    /**
     * FLOW：
     *  - 屋顶透明(close时必须归还)
     *  - TWEEN定位
     *  - 控制器设置
     *  - 键盘设置(待定)
     */
    const { building, controls, staff, camera } = params;
    const { transformControls, orbitControls } = controls;
    // 屋顶透明(断言类型)
    building instanceof GreenHouse && building.setProofOpacity(0.2);
    // 定位相关
    const { center: buildingCenter } = building.getInfo();
    const { center } = staff.getInfo();
    const endPos = new Vector3(center.x, buildingCenter.y * 0.9, center.z);
    const endTarget = new Vector3(center.x, 0, center.z);
    createCameraTween({
      camera,
      controls: orbitControls,
      endPos,
      endTarget,
      duration: 1000,
    });

    // 控制器相关

    controls.enableTransformModeMenu({
      initialMode: 'translate',
      visibleModes: [
        {
          mode: 'rotate',
          callback: () => {
            transformControls.rotationSnap = Math.PI / 2;
            transformControls.showX = false;
            transformControls.showY = true;
            transformControls.showZ = false;
          },
        },
        {
          mode: 'translate',
          callback: () => {
            transformControls.showX = true;
            transformControls.showY = false;
            transformControls.showZ = true;
          },
        },
        {
          mode: 'scale',
          callback: () => {
            transformControls.scaleSnap = 0.1;
            transformControls.showX = false;
            transformControls.showY = false;
            transformControls.showZ = true;
          },
        },
      ],
    });

    // transfrom跟随(跟随中心)

    // 键盘操作相关
  },
};
